/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import QtQml 2.12
import QtQuick.Layouts 1.12
import "."

Item {
    width: 450 * Style.widthScaleFactor;
    height: 120 * Style.heightScaleFactor;
    property string system: "24";
    property string hour;
    property string minute;
    property int hournumber;

    Timer {
        id: gettime;
        interval: 500;
        running: true;
        repeat: true;
        onTriggered: {
            hour = Qt.formatTime(new Date(),"hh");
            minute = Qt.formatTime(new Date(),"mm");
            if(system === "12") {
                hournumber = Number(hour);
                if(hournumber > 12) {
                    hournumber -= 12;
                    hour = hournumber.toString();
                }
                time.text = hour + ":" + minute;
            }
            else {
                time.text = hour + ":" + minute;
            }
            ap.text = Qt.formatTime(new Date(),"ap");
            date.text = Qt.formatDate(new Date(),"ddd  MM.dd");
        }
    }
    RowLayout {
        anchors.fill: parent
        spacing: 0
        Text {
            id: time
            color: "white"; font.pointSize: Style.widthScaleFactor * 72; font.bold: true;
            horizontalAlignment: Qt.AlignLeft; verticalAlignment: Qt.AlignHCenter
        }

        ColumnLayout {
            spacing: 0
            Layout.fillHeight: false
            Layout.fillWidth: true
            Layout.alignment: Qt.AlignVCenter

            Text {
                id: ap
                font.pointSize: Style.widthScaleFactor * 24
                color: "white"; width: Style.widthScaleFactor * parent.width; height: Style.heightScaleFactor * 60
                horizontalAlignment: Qt.AlignRight; verticalAlignment: Qt.AlignVCenter
            }
            Text {
                id: date
                color: "white"; font.pointSize: Style.widthScaleFactor * 24
                width: Style.widthScaleFactor * parent.width; height: Style.heightScaleFactor * 65
                horizontalAlignment: Qt.AlignRight; verticalAlignment: Qt.AlignVCenter
            }
        }
    }

    Component.onCompleted: gettime.start();
}
